package com.jxust.mapper;

import com.jxust.pojo.Emp;
import com.jxust.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

//员工mapper
@Mapper
public interface EmpMapper {

    //-------------------------------原始人------------------
//    @Select("select e.* ,d.name from emp e left join dept d on e.dept_id=d.id")
//    public Long count();
//
//    @Select("select e.* ,d.name deptName from emp e left join dept d on e.dept_id=d.id order by e.update_time desc " +
//            "limit #{start},#{pageSize}")
//    public List<Emp> list(@Param("start") Integer start , @Param("pageSize") Integer pageSize);
    List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 批量删除员工信息
     */
    void deleteByIds(@Param("ids") List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();


    List<Map<String, Object>> countEmpGenderData();

    @Select("SELECT id, name FROM emp WHERE job = 1 ")
    List<Emp> listMasters();


    /*
    * @Description: 根据用户名和密码查询员工信息
     */
    @Select("SELECT id, username,name FROM emp WHERE username = #{username} AND password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}
